package award

import (
	"encoding/json"
	"errors"
	"fmt"
	"kop/modules/configuration/client"
	"kop/util/log"
)

func init() {

	var b = client.Load("ConquerAwardBag")
	if err := json.Unmarshal(b, &Configs); err != nil {
		panic(err)
	}

	log.Info("Load ConquerAwardBag.json success.")
}

type Conf struct {
	ID int32 // 索引ID：无含义
	//AwardBagID int32 // 奖励包ID
	Weight    int32 // 权重
	AwardType int32 // 奖励类型
	Value     int32 // 奖励参数
	CountMin  int32 // 最小数量
	CountMax  int32 // 最大数量
}

func (b Conf) GetWeight() int32 {
	return b.Weight
}

func (b Conf) GetID() int32 {
	return b.ID
}

var Configs = map[int32]Conf{}

func GetAwardID(ID int32) (Conf, error) {

	var conf, ok = Configs[ID]
	if ok {
		return conf, nil
	}

	return Conf{}, errors.New(fmt.Sprintf("Conquer Award not found [%d]", ID))
}
